<template>
  <div>
    <van-picker
      title="更新性别"
      show-toolbar
      :columns="columns"
      :default-index="value"
      @confirm="onConfirm"
      @cancel="$emit('close-popup')"
    />
  </div>
</template>

<script>
import { setUserProfile } from '@/api/user.js'
export default {
  data () {
    return {
      columns: ['男', '女']
    }
  },

  created () {

  },

  props: {
    value: {
      type: Number,
      required: true
    }
  },

  methods: {
    async onConfirm (val, index) {
      try {
        await setUserProfile({
          gender: index
        })
        this.$toast('修改成功')
        this.$emit('close-popup')
        this.$emit('input', index)
      } catch (err) {
        this.$toast('修改失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
